package com.controller;

import com.dto.excution.ListExcution;
import com.dto.in.OrderListInfo;
import com.entity.*;
import com.enums.ListEnum;
import com.service.OrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "订单记录")
    @PostMapping(value = "/orderRecord")
    @ResponseBody
    public ListExcution<List<RecordInfo>> orderRecord(Integer stdUserId,Integer teaUserId) {
        List<RecordInfo> recordInfo = orderService.orderRecord(stdUserId,teaUserId);
        return new ListExcution<List<RecordInfo>>(recordInfo, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查询是否存在课时价格")
    @PostMapping(value = "/findTeacherHourPrice")
    @ResponseBody
    public ListExcution findTeacherHourPrice(Integer teaUserId) {
        BigDecimal money = orderService.findTeacherHourPrice(teaUserId);
        return new ListExcution(money, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查自己个儿的信息 家长")
    @PostMapping(value = "/findZiJiGerMsg")
    @ResponseBody
    public ListExcution<StudentInfo> findZiJiGerMsg(Integer userId) {
        StudentInfo info = orderService.findZiJiGerMsg(userId);
        return new ListExcution<StudentInfo>(info, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "订单详情")
    @PostMapping(value = "/orderDetails")
    @ResponseBody
    public ListExcution<RecordInfo>orderDetails(Integer OrderId){
        RecordInfo recordInfo=orderService.orderDetails(OrderId);
        return new ListExcution<RecordInfo>(recordInfo, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "取消订单")
    @PostMapping(value = "/deleteOrder")
    @ResponseBody
    public ListExcution<Void> deleteOrder(Integer OrderId){
        int deleorder=orderService.deleteOrder(OrderId);
        if(deleorder > 0){
            return new ListExcution<Void>(null, ListEnum.SUCCESS);
        }else{
            return new ListExcution<Void>(null, ListEnum.FAIL);
        }
    }

    @ApiOperation(value = "新增订单")
    @PostMapping(value = "/addOrder")
    @ResponseBody
    public ListExcution addOrder(OrderListInfo orderListInfo){
        int addorder=orderService.addOrder(orderListInfo);
        if(addorder > 0){
            return new ListExcution(addorder, ListEnum.SUCCESS);
        }else{
            return new ListExcution(addorder, ListEnum.FAIL);
        }
    }

    @ApiOperation(value = "开始上课/修改状态")
    @PostMapping(value = "/updateRecordStatus")
    @ResponseBody
    public ListExcution<Void> updateRecordStatus(Integer id){
        int deit=orderService.updateRecordStatus(id);
        if(deit > 0){
            return new ListExcution<Void>(null, ListEnum.SUCCESS);
        }else{
            return new ListExcution<Void>(null, ListEnum.FAIL);
        }
    }

    @ApiOperation(value = "查看订单信息 //家长端购买后")
    @PostMapping(value = "/findOrderPayMsg")
    @ResponseBody
    public ListExcution<ParentMsgInfo> findOrderPayMsg(Integer id){
        ParentMsgInfo info=orderService.findOrderPayMsg(id);
        return new ListExcution<ParentMsgInfo>(info, ListEnum.SUCCESS);

    }

    @ApiOperation(value = "查看订单信息 //家长端购买后")
    @PostMapping(value = "/updateOrderStatus")
    @ResponseBody
    public ListExcution<Void> updateOrderStatus(Integer id,String nonceStr,Integer userId,BigDecimal yb,BigDecimal fhPrice,BigDecimal totalPrice,BigDecimal zzPrice){
        int success = orderService.updateOrderStatus(id,nonceStr,userId,yb,fhPrice,totalPrice,zzPrice);
        return new ListExcution<Void>(null, ListEnum.SUCCESS);

    }

    @ApiOperation(value = "查看小订单")
    @PostMapping(value = "/findSmallOrder")
    @ResponseBody
    public ListExcution<List<RecordOrderInfo>> findSmallOrder(Integer id){
        List<RecordOrderInfo> list = orderService.findSmallOrder(id);
        return new ListExcution<List<RecordOrderInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "确认下课")
    @PostMapping(value = "/confirmEnd")
    @ResponseBody
    public ListExcution confirmEnd(Integer id,Integer recordId,BigDecimal price){
        int count = orderService.confirmEnd(id,recordId,price);
        return new ListExcution(count, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "添加退款申请")
    @PostMapping(value = "/insertRefund")
    @ResponseBody
    public ListExcution insertRefund(Integer recordId){
        int count = orderService.insertRefund(recordId);
        if(count > 0){
            return new ListExcution(null, ListEnum.SUCCESS);
        }else{
            return new ListExcution(null, ListEnum.FAIL);
        }

    }

    @ApiOperation(value = "保存路线")
    @PostMapping(value = "/savePath")
    @ResponseBody
    public ListExcution savePath(Integer recordId,String thisLocation,String thisLat,String thisLog,String aimLocation,String aimLat,String aimLog){
        int count = orderService.savePath(recordId,thisLocation,thisLat,thisLog,aimLocation,aimLat,aimLog);
        return new ListExcution(count, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查天排行榜")
    @PostMapping(value = "/findRanking")
    @ResponseBody
    public ListExcution<List<LoginInfo>> findRanking(Integer limit,Integer type){
        List<LoginInfo> list = orderService.findRanking(limit,type);
        return new ListExcution<List<LoginInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查记录列表")
    @PostMapping(value = "/findJiLuList")
    @ResponseBody
    public ListExcution<List<LoginInfo>> findJiLuList(Integer limit){
        List<LoginInfo> list = orderService.findJiLuList(limit);
        return new ListExcution<List<LoginInfo>>(list, ListEnum.SUCCESS);
    }


}
